package com.yadang.homework;

import java.util.ArrayList;

import java.util.Collection;

import java.util.HashMap;


import java.util.Iterator;

import java.util.List;

import java.util.Map;

import java.util.Set;

/**
 * @author: 亚当
 * @date: 2023年02月05日 18:12
 * @package: com.yadang.homework
 * @Description: 如何将map集合中相同value的key取出来
 */
public class Map1 {

    public static void main(String[] args) {

        //建立一个hashMap,数值类型为String
        Map<String,String> m1 = new HashMap<String,String>();
        m1.put("one","黄");
        m1.put("two","河");
        m1.put("three","涛");
        m1.put("four","涛");
        m1.put("five","h");
        m1.put("six","牛");
        m1.put("seven","B");
        //建立一个数组用来存储m1的数值
        List<String> al1 = new ArrayList<String>();
        //遍历m1的值，然后赋值到al1
        Collection values = m1.values();
        for(Iterator iterator1 = values.iterator();iterator1.hasNext();){
            al1.add((String) iterator1.next());
        }
        //System.out.println(al1.size());
        //找到values值相等的str1
        String str1 = null;
        for(int i=0;i<al1.size()-1;i++){
            for(int j=i+1;j<al1.size();j++){
                if(al1.get(i)==al1.get(j)){
                    System.out.println(al1.get(i));
                    str1 = al1.get(i);
                }
            }
        }
        //输出等于strl值的key值
        Collection col1 = m1.entrySet();
        String str2 = null;
        for(Iterator ite2 = col1.iterator();ite2.hasNext();){
            Object obj = ite2.next();
            str2 = obj.toString();
            if(str1.equals(str2.substring(str2.indexOf("=")+1,str2.length()))){
                System.out.println(str2.substring(0,str2.lastIndexOf("=")));
            }
        }
    }
}